Replace Qwen3.5 FLA paths with Attention Gym - #4389
Conversation
e341e0e to
436eeb9
Compare
| key_head_dim=128, | ||
| value_head_dim=128, |
There was a problem hiding this comment.
is this because of minimal block size that works with attn-gym kernels? Feels Blackwell only?
There was a problem hiding this comment.
yeah this is restriction for our kernels right now; while originally motivated by blackwell this will take some more work if we want to open up
| self.num_speculative_tokens = ( | ||
| speculative_config.num_speculative_tokens if speculative_config else 0 | ||
| ) | ||
| if self.num_speculative_tokens != 0: |
There was a problem hiding this comment.
How hard to make a kernel support speculative decoding? I want to learn what features does a kernel need to support this
There was a problem hiding this comment.
just now looking at this;
it looks like vllm basically adds (n_speculated_tokens, state) so expands the state cache so the potential tokens can update their slots. If we only accept M tokens then the N_speculated - M gets drop and then I think copy over M to be the base;
This is doable, would require a decent amount of changes but forsure doable feel free to open an issue in attn_gym
4c1b827 to
9a41a7d
Compare
3c22e6f to
e39f387
Compare
Use Attention Gym for Qwen3.5 GDN training, batch-invariant backward recomputation, recurrent execution, decode, and paged chunk prefill. The paged prefill path advances vLLM SSM cache slots in place, eliminating the previous gather/chunk/scatter copies and preserving the shared [slots, H, V, K] layout across prefill and decode. Remove the now-unused FLA backend selection and dependency, normalize Q/K explicitly at the Attention Gym boundary, and update debug configurations to the fused backend K=V=128 contract while retaining two key heads for TP=2 coverage. On GB200, isolated paged-prefill measurements reduced GPU time by 18.2-31.7% across five T=1024-8192, N=1-64 cases. A matched end-to-end vLLM debug-model comparison at prompt=128, generation=64, and batch sizes 1-16 improved output throughput by 1.5-6.4%. ```bash PYTHONPATH=/home/drisspg/meta/attention-gym-paged-gdn:/home/drisspg/meta/torchtitan pytest -q tests/unit_tests/gpu/test_qwen3_5_deltanet.py tests/unit_tests/test_qwen3_5_mrope_positions.py -x PYTHONPATH=/home/drisspg/meta/attention-gym-paged-gdn:/home/drisspg/meta/torchtitan pytest -q tests/unit_tests/cpu/test_state_dict_keys.py tests/unit_tests/cpu/test_integration_test_definitions.py tests/unit_tests/cpu/test_train_spec.py -x PYTHONPATH=/home/drisspg/meta/torchtitan:/home/drisspg/meta/attention-gym-paged-gdn torchrun --nproc-per-node=2 -m pytest torchtitan/experiments/rl/tests/test_bitwise_parity.py::TestBitwiseParityQwen35DebugVarlen -v -s ```
## Human Note ## Agent note Use Attention Gym's paged causal convolution API for vLLM multi-token prefill. The operation reads fresh or resumed cache slots directly and advances them in place, removing the remaining temporary history allocation, gather, host-syncing continuation check, and final-state scatter from Qwen3.5 serving. ## Performance On GB200 at the TP=2-local Qwen3.5 shape (C=4096, W=4, BF16), direct paging reduced convolution prefill GPU time by 43.8-79.4% for fresh prompts and 46.2-80.4% for resumed prefixes across N=1-64 and 128-512 tokens per sequence. ## Test Plan ```bash PYTHONPATH=/home/drisspg/meta/attention-gym:/home/drisspg/meta/torchtitan pytest -q tests/unit_tests/gpu/test_qwen3_5_deltanet.py tests/unit_tests/test_qwen3_5_mrope_positions.py -x PYTHONPATH=/home/drisspg/meta/attention-gym .venv/bin/pytest -q -n 6 test/test_short_conv_cute.py test/linear/test_gdn_chunk_fused.py test/test_namespaces.py PYTHONPATH=/home/drisspg/meta/torchtitan:/home/drisspg/meta/attention-gym torchrun --nproc-per-node=2 -m pytest -q torchtitan/experiments/rl/tests/test_bitwise_parity.py::TestBitwiseParityQwen35DebugVarlen ```
## Human Note ## Agent note Remove the redundant subprocess import test, narrow the recurrent backward smoke check to the decay gradient it is intended to protect, and use the current expected vLLM batch-invariance import path directly instead of carrying compatibility logic for an older package layout. ## Test Plan ```bash PYTHONPATH=/home/drisspg/meta/attention-gym:/home/drisspg/meta/torchtitan pytest -q tests/unit_tests/gpu/test_qwen3_5_deltanet.py tests/unit_tests/test_qwen3_5_mrope_positions.py -x PYTHONPATH=/home/drisspg/meta/torchtitan python -c 'from torchtitan.experiments.rl.batch_invariance import patch_bmm_for_batch_invariance; patch_bmm_for_batch_invariance()' ```
e39f387 to
445ccc3
Compare
Human Note
Lots of data; we added the paged form to conv for q_tokens > 1 and also added supprot for chunk_gdn that works on blackwell and hopper, verifying on hopper now
Agent note
This incorporates Angel Li's Attention Gym migration from #4363 and extends it so the resulting
change can land as one self-contained PR against
main. It uses Attention Gym for Qwen3.5 GDNtraining, batch-invariant backward recomputation, recurrent execution, decode, and paged prefill.
The vLLM path advances both convolution and SSM cache slots in place. This removes the prior
prefill-time temporary state allocations, grouped-head expansion, gather/scatter copies, transposes,
and host-syncing continuation check while preserving the shared
[slots, H, V, K]SSM layout.The paged operations landed in Attention Gym as
meta-pytorch/attention-gym#431 and
meta-pytorch/attention-gym#432.
The now-unused FLA backend selection and direct dependency are removed. Q/K normalization is explicit
at the Attention Gym boundary, and debug configurations use the fused backend's
K = V = 128contract while retaining two key heads for TP=2 coverage.
Performance
End-to-end vLLM: before either PR vs combined candidate
GB200, Qwen3.5 debug model with production GDN dimensions
K=V=128, prompt length 128, generationlength 64, TP=1, FULL_AND_PIECEWISE CUDA graphs, five measured rounds per engine launch. Three engine
launches were paired at the parent of #4363 (
9aadc3616) and the combined candidate; the table reportsmedian throughput across launches and the median paired change.
Process-level throughput varied, but every paired before/after launch improved at every batch size.
Hopper end-to-end vLLM: FLA parent vs combined candidate (September 1, 2026)
H100 80GB (SM90), Qwen3.5 debug model, BF16, prompt length 128, generation length 64,
TP=1, FULL_AND_PIECEWISE CUDA graphs, one warmup and five synchronized measured rounds per
batch. The process-level A-B-A comparison used the pre-PR FLA parent (
9aadc3616, FLA 0.5.2)and the combined candidate with Attention Gym
e429589.The parent debug config defaults to
K=V=64, so the baseline was explicitly rebuilt withK=V=128to match the candidate and production GDN dimensions. This compares the complete FLAGDN + convolution stack with the Attention Gym paged GDN + paged convolution stack, rather than
an isolated GDN kernel. The Attention Gym column gives the range of the two bracketing candidate
medians; change uses their mean.
The matched Hopper result is roughly tied: bracket means favor Attention Gym by 0.61-2.81%, but
process-level variation overlaps FLA at batches 8 and 16. The H100 validation also covered
paged-state boundaries, mixed prefill/decode scheduling, trainer/generator bitwise parity, fused
GDN backward, an AdamW update, and post-update weight synchronization into vLLM.
Hopper training convergence (September 1, 2026)
A deterministic 100-step Qwen3.5 trainer run used the same
K=V=128architecture, exact initialweights, fixed packed C4 batches, AdamW schedule, gradient clipping, and held-out evaluation every
10 steps. Both models had 138,074,416 parameters and the same initial-state and corpus SHA256 hashes.
Train-loss correlation was
0.99999999496with maximum absolute delta0.001055; held-out-losscorrelation was
0.99999999772with maximum delta0.000473. Gradient-norm correlation was0.99995874, all metrics remained finite, and the final gradient-norm delta was zero. This foundno meaningful bounded convergence regression while exercising real forward, fused GDN backward,
global clipping, AdamW updates, and held-out evaluation.
This is a debug-model C4 convergence/regression run, not long-horizon production RL convergence.
GDN prefill ablation
GB200, fixed-pointer warm-cache,
HK=8,H=16,K=V=128, BF16 QKV, FP32 state, five interleavedrounds of 30 iterations:
Convolution prefill ablation
At the Qwen3.5 TP=2-local shape (
C=4096,W=4, BF16), direct paging reduced GPU time by43.8-79.4% for fresh prompts and 46.2-80.4% for resumed prefixes across N=1-64 and 128-512
tokens per sequence.
Paged-state continuity
The non-batch-invariant vLLM path passed a 15-case boundary sweep at 528, 1056, and 1584 tokens
with continuation lengths 1, 63, 64, 65, and 527. Every cached/fresh pair generated identical token
IDs; the maximum logprob delta was
1.713e-3. A batch mixing fresh and resumed prefills passed, anda forced mixed decode+prefill step matched standalone token IDs with maximum deltas
1.385e-3and9.537e-7.Perfetto traces
CUDA Graph replay traces use
enable_annotations=Trueand nestedmark_kernelsscopes, thenmerge-traces --alignto place before/after variants on labeled process tracks:Eager execution traces:
Test Plan